define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'visit/log/index' + location.search,
                    add_url: 'visit/log/add',
                    edit_url: 'visit/log/edit',
                    del_url: 'visit/log/del',
                    multi_url: 'visit/log/multi',
                    import_url: 'visit/log/import',
                    table: 'visit_log',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'site_id', title: __('站点'), formatter: Controller.api.formatter.site_name,searchList: {
                                1:'星湖路养老服务站',
                                2:'洪湖东路养老服务站',
                                3:'天宫殿养老服务中心',
                                4:'玉兰路养老服务站',
                                5:'东湖南路养老服务站',
                                6:'东湖北路养老服务站',
                                7:'梧桐路养老服务站',
                                8:'丁香路养老服务站',
                            }},
                        {field: 'visit', title: __('Visit'), operate: false},
                        {field: 'log_date', title: __('Log_date'), operate:false, addclass:'datetimerange', autocomplete:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            formatter: {
                site_name: function (value, row, index) {
                    var name = '';
                    switch (row.site_id){
                        case 1:
                            name ='星湖路养老服务站';
                            break;
                        case 2:
                            name ='洪湖东路养老服务站';
                            break;
                        case 3:
                            name ='天宫殿养老服务中心';
                            break;
                        case 4:
                            name ='玉兰路养老服务站';
                            break;
                        case 5:
                            name ='东湖南路养老服务站';
                            break;
                        case 6:
                            name ='东湖北路养老服务站';
                            break;
                        case 7:
                            name ='梧桐路养老服务站';
                            break;
                        default:
                            name ='丁香路养老服务站';
                    }
                    return '<span style="white-space: nowrap;">'+ name +'</span>';
                }
            },
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
